// Cesare


// Merging

/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.viper;

import com.example.android.viper.R;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

/**
 * Snake: a simple game that everyone can enjoy.
 * 
 * This is an implementation of the classic Game "Snake", in which you control a
 * serpent roaming around the garden looking for apples. Be careful, though,
 * because when you catch one, not only will you become longer, but you'll move
 * faster. Running into yourself or the walls will end the game.
 * 
 */
public class Viper extends Activity
{

	private ViperView mViperView;

	private static String ICICLE_KEY = "viper-view";

	/**
	 * Called when Activity is first created. Turns off the title bar, sets up
	 * the content views, and fires up the SnakeView.
	 * 
	 */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);

		setContentView(R.layout.snake_layout);

		mViperView = (ViperView) findViewById(R.id.snake);
		mViperView.setTextView((TextView) findViewById(R.id.text));

		if (savedInstanceState == null)
		{
			// We were just launched -- set up a new game
			mViperView.setMode(ViperView.READY);
		} else
		{
			// We are being restored
			Bundle map = savedInstanceState.getBundle(ICICLE_KEY);
			if (map != null)
			{
				mViperView.restoreState(map);
			} else
			{
				mViperView.setMode(ViperView.PAUSE);
			}
		}
	}

	@Override
	protected void onPause()
	{
		super.onPause();
		// Pause the game along with the activity
		mViperView.setMode(ViperView.PAUSE);
	}

	@Override
	public void onSaveInstanceState(Bundle outState)
	{
		// Store the game state
		outState.putBundle(ICICLE_KEY, mViperView.saveState());
	}
	
	@Override
	public void onConfigurationChanged (Configuration newConfig)
	{
		mViperView.setOrientation(newConfig.orientation);
		//Log.d("ViperView","Conf changed");
		super.onConfigurationChanged(newConfig);
	}
}
